﻿namespace Sidvall.FileSystemManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class UserConfiguration : global::Sidvall.FileSystemManager.UI.Entities.Core.BusinessBase, global::Sidvall.FileSystemManager.Data.IUserConfiguration
    {
        #region Business Members

        #region CleanConfigContext

        private string _CleanConfigContext = string.Empty;
        partial void OnBeforeCleanConfigContextPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeCleanConfigContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterCleanConfigContextPropertyChanged();
        public string CleanConfigContext
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_CleanConfigContext);
                OnBeforeCleanConfigContextPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _CleanConfigContext);
                OnBeforeCleanConfigContextPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("CleanConfigContext", eventData.Value, true, true, true);
                    OnAfterCleanConfigContextPropertyChanged();
                }
            }
        }

        #endregion
        #region Name

        private string _Name = string.Empty;
        partial void OnBeforeNamePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Name);
                OnBeforeNamePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                OnBeforeNamePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Name", eventData.Value, true, true, true);
                    OnAfterNamePropertyChanged();
                }
            }
        }

        #endregion
        #region RenameConfigContext

        private string _RenameConfigContext = string.Empty;
        partial void OnBeforeRenameConfigContextPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeRenameConfigContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterRenameConfigContextPropertyChanged();
        public string RenameConfigContext
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_RenameConfigContext);
                OnBeforeRenameConfigContextPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _RenameConfigContext);
                OnBeforeRenameConfigContextPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("RenameConfigContext", eventData.Value, true, true, true);
                    OnAfterRenameConfigContextPropertyChanged();
                }
            }
        }

        #endregion
        #region SearchConfigContext

        private string _SearchConfigContext = string.Empty;
        partial void OnBeforeSearchConfigContextPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeSearchConfigContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSearchConfigContextPropertyChanged();
        public string SearchConfigContext
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_SearchConfigContext);
                OnBeforeSearchConfigContextPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _SearchConfigContext);
                OnBeforeSearchConfigContextPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("SearchConfigContext", eventData.Value, true, true, true);
                    OnAfterSearchConfigContextPropertyChanged();
                }
            }
        }

        #endregion
        #region StartPageId

        private global::Sidvall.FileSystemManager.Data.PageType _StartPageId = global::Sidvall.FileSystemManager.Data.PageType.Rename;
        partial void OnBeforeStartPageIdPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.FileSystemManager.Data.PageType> eventData);
        partial void OnBeforeStartPageIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.FileSystemManager.Data.PageType> eventData);
        partial void OnAfterStartPageIdPropertyChanged();
        public global::Sidvall.FileSystemManager.Data.PageType StartPageId
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.FileSystemManager.Data.PageType> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.FileSystemManager.Data.PageType>(_StartPageId);
                OnBeforeStartPageIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.FileSystemManager.Data.PageType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.FileSystemManager.Data.PageType>(value, _StartPageId);
                OnBeforeStartPageIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("StartPageId", eventData.Value, true, true, true);
                    OnAfterStartPageIdPropertyChanged();
                }
            }
        }

        #endregion
        #region UserConfigurationId

        private System.Nullable<int> _UserConfigurationId = null;
        partial void OnBeforeUserConfigurationIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData);
        partial void OnBeforeUserConfigurationIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterUserConfigurationIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<int> UserConfigurationId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<int>>(_UserConfigurationId);
                OnBeforeUserConfigurationIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _UserConfigurationId);
                OnBeforeUserConfigurationIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("UserConfigurationId", eventData.Value, true, true, true);
                    OnAfterUserConfigurationIdPropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.UserConfigurationManager.GetKey(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.UserConfigurationManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.UserConfigurationManager.AcceptChanges(this);
        }

        #endregion
        #region Copy

        public UserConfiguration Copy()
        {
            return Copy(null);
        }
        partial void OnAfterCopy(UserConfiguration destination, Sidvall.Data.CopySettings settings);
        public UserConfiguration Copy(Sidvall.Data.CopySettings settings)
        {
            var item = global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.UserConfigurationManager.Copy(this, settings);
            OnAfterCopy(item, settings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.FileSystemManager.Data.IUserConfiguration item)
        {
            Import(item, null);
        }
        partial void OnAfterImport(global::Sidvall.FileSystemManager.Data.IUserConfiguration source, Sidvall.Data.CopySettings settings);
        public void Import(global::Sidvall.FileSystemManager.Data.IUserConfiguration item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.UserConfigurationManager.Import(this, item, settings);
            OnAfterImport(item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.UserConfigurationManager.ValidateAsync(this, context).ConfigureAwait(false);
            await ValidateAsync(context).ConfigureAwait(false);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync().ConfigureAwait(false);
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.UserConfigurationManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.UserConfigurationManager.Initialize(this, settings);
        }

        #endregion
        
        #region IUserConfiguration Members

        string global::Sidvall.FileSystemManager.Data.IUserConfiguration.CleanConfigContext
        {
            get
            {
                return this._CleanConfigContext;
            }
            set
            {
                this._CleanConfigContext = value;
            }
        }
        string global::Sidvall.FileSystemManager.Data.IUserConfiguration.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        string global::Sidvall.FileSystemManager.Data.IUserConfiguration.RenameConfigContext
        {
            get
            {
                return this._RenameConfigContext;
            }
            set
            {
                this._RenameConfigContext = value;
            }
        }
        string global::Sidvall.FileSystemManager.Data.IUserConfiguration.SearchConfigContext
        {
            get
            {
                return this._SearchConfigContext;
            }
            set
            {
                this._SearchConfigContext = value;
            }
        }
        global::Sidvall.FileSystemManager.Data.PageType global::Sidvall.FileSystemManager.Data.IUserConfiguration.StartPageId
        {
            get
            {
                return this._StartPageId;
            }
            set
            {
                this._StartPageId = value;
            }
        }
        System.Nullable<int> global::Sidvall.FileSystemManager.Data.IUserConfiguration.UserConfigurationId
        {
            get
            {
                return this._UserConfigurationId;
            }
            set
            {
                this._UserConfigurationId = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public UserConfiguration()
        {
        }

        public UserConfiguration(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}